//
//  main.swift
//  SwiftUnsafePointer
//
//  Created by edy on 2024/5/30.
//  Copyright © 2024 Riven. All rights reserved.
//  简书教程（[Swift] 指针UnsafePointer）： https://www.jianshu.com/p/e90393ba2aea
//  Swift中指针UnsafePointer的常见用法：https://www.cnblogs.com/zhou--fei/p/17652559.html

import Foundation

//let t = count ~= 2
//
//print(t)

//testRawPointer()

print("-----------------------------------")

//testTypePointer()

print("-----------------------------------")

//testRawPointerToTypePointer()

//testDemo()

//testCSampleDemo()

var numbers = [1, 2, 3]
//var numbers = (1, 2, 3)
//let tp = withUnsafePointer(to: number) { p in
//    return UnsafeRawPointer(p).withMemoryRebound(to: Int.self, capacity: 3) { pointer in
//        return pointer
//    }
//}


//let pIntRaw = UnsafeRawPointer(numbers).withMemoryRebound(to: Int.self, capacity: 3) { pointer in
//    return pointer
//}

//let pIntRaw = numbers.withUnsafeBufferPointer { pBuf in
//    return UnsafeRawPointer(pBuf).withMemoryRebound(to: Int.self, capacity: 3) { pointer in
//        return pointer
//    }
//}

//var pRaw = withUnsafeMutableBytes(of: &numbers) { pbuf in
//    for i in pbuf {
//        
//        print(i)
//    }
//    return pbuf
//}
//print(pRaw)
//let tmp = UnsafeMutableRawPointer(pRaw).bindMemory(to: Int.self, capacity: count)
//let tp = UnsafePointer<Int>(pRaw.baseAddress!)
//printInt(atAddress: tp)

//let t = numbers.withUnsafeBufferPointer { pbuf in
//    print(pbuf)
//    for i in pbuf {
//        print(i)
//    }
//    return pbuf.baseAddress!
//}
//let ttp = UnsafePointer<Int>(t)
//printInt(atAddress: ttp)

testTupleIteration()
